<!--
 * @Author: your name
 * @Date: 2021-09-07 11:46:55
 * @LastEditTime: 2021-09-07 14:20:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day12\10-键盘事件.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>键盘事件</title>
</head>

<body>
    <div></div>
</body>
<script>
    // keydown 按下键盘任意键触发 如果按住不放会重复触发
    // document.onkeydown = function() {
    //         console.log("有键被按下" + event.keyCode);
    //     }
    // keypress 按下键盘字符键触发
    document.onkeypress = function() {
            console.log("有键被按下" + event.keyCode);
        }
        //keyup    释放按键时触发
    document.onkeyup = function() {
            console.log("释放按键" + event.keyCode);
        }
        //特殊按键处理
    document.onkeydown = function(event) {
        if (event.shiftKey) {
            console.log("shift被按下")
        }
        if (event.ctrlKey) {
            console.log("ctrl被按下")
        }
        if (event.altKey) {
            console.log("alt被按下")
        }
        if (event.metaKey) {
            console.log("meta被按下")
        }

    }
</script>

</html>